home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 001-025 / disk_002 / microemacs / spawn.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  7KB  |  224 lines

  1. /*
  2.  * The routines in this file are called to create a subjob running a command
  3.  * interpreter. This code is a big fat nothing on CP/M-86. You lose.
  4.  */
  5. #include        <stdio.h>
  6. #include        "ed.h"
  7.  
  8. #if     AMIGA
  9. #define  NEW   1006
  10. #endif
  11.  
  12. #if     VMS
  13. #define EFN     0                               /* Event flag.          */
  14.  
  15. #include        <ssdef.h>                       /* Random headers.      */
  16. #include        <stsdef.h>
  17. #include        <descrip.h>
  18. #include        <iodef.h>
  19.  
  20. extern  int     oldmode[];                      /* In "termio.c"        */
  21. extern  int     newmode[];                      /* In "termio.c"        */
  22. extern  short   iochan;                         /* In "termio.c"        */
  23. #endif
  24.  
  25. #if     MSDOS
  26. #include        <dos.h>
  27. #endif
  28.  
  29. #if     V7
  30. #include        <signal.h>
  31. #endif
  32.  
  33. /*
  34.  * Create a subjob with a copy of the command intrepreter in it. When the
  35.  * command interpreter exits, mark the screen as garbage so that you do a full
  36.  * repaint. Bound to "C-C". The message at the start in VMS puts out a newline.
  37.  * Under some (unknown) condition, you don't get one free when DCL starts up.
  38.  */
  39. spawncli(f, n)
  40. {
  41. #if     AMIGA
  42.         long newcli;
  43.  
  44.         newcli = Open("CON:1/1/639/199/MicroEmacs Subprocess", NEW);
  45.         mlwrite("[Starting new CLI]");
  46.         sgarbf = TRUE;
  47.         Execute("", newcli, 0);
  48.         Close(newcli);
  49.         return(TRUE);
  50. #endif
  51.  
  52. #if     V7
  53.         register char *cp;
  54.         char    *getenv();
  55. #endif
  56. #if     VMS
  57.         movecursor(term.t_nrow, 0);             /* In last line.        */
  58.         mlputs("[Starting DCL]\r\n");
  59.         (*term.t_flush)();                      /* Ignore "ttcol".      */
  60.         sgarbf = TRUE;
  61.         return (sys(NULL));                     /* NULL => DCL.         */
  62. #endif
  63. #if     CPM
  64.         mlwrite("Not in CP/M-86");
  65. #endif
  66. #if     MSDOS
  67.         movecursor(term.t_nrow, 0);             /* Seek to last line.   */
  68.         (*term.t_flush)();
  69.         sys("\\command.com", "");               /* Run CLI.             */
  70.         sgarbf = TRUE;
  71.         return(TRUE);
  72. #endif
  73. #if     V7
  74.         movecursor(term.t_nrow, 0);             /* Seek to last line.   */
  75.         (*term.t_flush)();
  76.         ttclose();                              /* stty to old settings */
  77.         if ((cp = getenv("SHELL")) != NULL && *cp != '\0')
  78.                 system(cp);
  79.         else
  80.                 system("exec /bin/sh");
  81.         sgarbf = TRUE;
  82.         sleep(2);
  83.         ttopen();
  84.         return(TRUE);
  85. #endif
  86. }
  87.  
  88. /*
  89.  * Run a one-liner in a subjob. When the command returns, wait for a single
  90.  * character to be typed, then mark the screen as garbage so a full repaint is
  91.  * done. Bound to "C-X !".
  92.  */
  93. spawn(f, n)
  94. {
  95.         register int    s;
  96.         char            line[NLINE];
  97. #if     AMIGA
  98.         long newcli;
  99.  
  100.         newcli = Open("CON:1/1/639/199/MicroEmacs Subprocess", NEW);
  101.         if ((s=mlreply("CLI command: ", line, NLINE)) != TRUE)
  102.                 return (s);
  103.         Execute(line,0,newcli);
  104.         Close(newcli);
  105.         while ((*term.t_getchar)() != '\r')     /* Pause.               */
  106.                 ;
  107.         sgarbf = TRUE;
  108.         return(TRUE);
  109. #endif
  110. #if     VMS
  111.         if ((s=mlreply("DCL command: ", line, NLINE)) != TRUE)
  112.                 return (s);
  113.         (*term.t_putchar)('\n');                /* Already have '\r'    */
  114.         (*term.t_flush)();
  115.         s = sys(line);                          /* Run the command.     */
  116.         mlputs("\r\n\n[End]");                  /* Pause.               */
  117.         (*term.t_flush)();
  118.         while ((*term.t_getchar)() != '\r')
  119.                 ;
  120.         sgarbf = TRUE;
  121.         return (s);
  122. #endif
  123. #if     CPM
  124.         mlwrite("Not in CP/M-86");
  125.         return (FALSE);
  126. #endif
  127. #if     MSDOS
  128.         if ((s=mlreply("MS-DOS command: ", line, NLINE)) != TRUE)
  129.                 return (s);
  130.         system(line);
  131.         while ((*term.t_getchar)() != '\r')     /* Pause.               */
  132.                 ;
  133.         sgarbf = TRUE;
  134.         return (TRUE);
  135. #endif
  136. #if     V7
  137.         if ((s=mlreply("! ", line, NLINE)) != TRUE)
  138.                 return (s);
  139.         (*term.t_putchar)('\n');                /* Already have '\r'    */
  140.         (*term.t_flush)();
  141.         ttclose();                              /* stty to old modes    */
  142.         system(line);
  143.         sleep(2);
  144.         ttopen();
  145.         mlputs("[End]");                        /* Pause.               */
  146.         (*term.t_flush)();
  147.         while ((s = (*term.t_getchar)()) != '\r' && s != ' ')
  148.                 ;
  149.         sgarbf = TRUE;
  150.         return (TRUE);
  151. #endif
  152. }
  153.  
  154. #if     VMS
  155. /*
  156.  * Run a command. The "cmd" is a pointer to a command string, or NULL if you
  157.  * want to run a copy of DCL in the subjob (this is how the standard routine
  158.  * LIB$SPAWN works. You have to do wierd stuff with the terminal on the way in
  159.  * and the way out, because DCL does not want the channel to be in raw mode.
  160.  */
  161. sys(cmd)
  162. register char   *cmd;
  163. {
  164.         struct  dsc$descriptor  cdsc;
  165.         struct  dsc$descriptor  *cdscp;
  166.         long    status;
  167.         long    substatus;
  168.         long    iosb[2];
  169.  
  170.         status = SYS$QIOW(EFN, iochan, IO$_SETMODE, iosb, 0, 0,
  171.                           oldmode, sizeof(oldmode), 0, 0, 0, 0);
  172.         if (status!=SS$_NORMAL || (iosb[0]&0xFFFF)!=SS$_NORMAL)
  173.                 return (FALSE);
  174.         cdscp = NULL;                           /* Assume DCL.          */
  175.         if (cmd != NULL) {                      /* Build descriptor.    */
  176.                 cdsc.dsc$a_pointer = cmd;
  177.                 cdsc.dsc$w_length  = strlen(cmd);
  178.                 cdsc.dsc$b_dtype   = DSC$K_DTYPE_T;
  179.                 cdsc.dsc$b_class   = DSC$K_CLASS_S;
  180.                 cdscp = &cdsc;
  181.         }
  182.         status = LIB$SPAWN(cdscp, 0, 0, 0, 0, 0, &substatus, 0, 0, 0);
  183.         if (status != SS$_NORMAL)
  184.                 substatus = status;
  185.         status = SYS$QIOW(EFN, iochan, IO$_SETMODE, iosb, 0, 0,
  186.                           newmode, sizeof(newmode), 0, 0, 0, 0);
  187.         if (status!=SS$_NORMAL || (iosb[0]&0xFFFF)!=SS$_NORMAL)
  188.                 return (FALSE);
  189.         if ((substatus&STS$M_SUCCESS) == 0)     /* Command failed.      */
  190.                 return (FALSE);
  191.         return (TRUE);
  192. }
  193. #endif
  194.  
  195. #if     MSDOS
  196. /*
  197.  * This routine, once again by Bob McNamara, is a C translation of the "system"
  198.  * routine in the MWC-86 run time library. It differs from the "system" routine
  199.  * in that it does not unconditionally append the string ".exe" to the end of
  200.  * the command name. We needed to do this because we want to be able to spawn
  201.  * off "command.com". We really do not understand what it does, but if you don't
  202.  * do it exactly "malloc" starts doing very very strange things.
  203.  */
  204. sys(cmd, tail)
  205. char    *cmd;
  206. char    *tail;
  207. {
  208. #if MWC_86
  209.         register unsigned n;
  210.         extern   char     *__end;
  211.  
  212.         n = __end + 15;
  213.         n >>= 4;
  214.         n = ((n + dsreg() + 16) & 0xFFF0) + 16;
  215.         return(execall(cmd, tail, n));
  216. #endif
  217.  
  218. #if LATTICE
  219.         return forklp(cmd, tail, NULL);
  220. #endif
  221. }
  222. #endif
  223.  
  224.